var PATH_PREFIX1 ="";

function setPathPrefix1(path){
	PATH_PREFIX1 =  path;
}
$(function() {
	// 给select2组件加载样式
	WASP_WIDGET.initializeSelectStyle();
	// 注册清空事件
    WASP_WIDGET.registerResetClearEvent();
    
    WASP_WIDGET.triggerDateStyleWithYMD($("#ruleBeginDate"));
    WASP_WIDGET.triggerDateStyleWithYMD($("#ruleEndDate"));
});

var $orderRiskMgrList = $('#orderRiskMgrList');

$(function() {
	$orderRiskMgrList.jqGrid({   
		url:PATH_PREFIX1+'orderRiskMgrListPage.do',    
		//caption:'订单风控管理列表<button type="button" class="btn btn-default btn-sm btn-small btn-fullscreen" title="" tabindex="-1"><i class="fa fa-arrows-alt icon-fullscreen"></i></button>',  
		datatype: "json",
		postData:{
			'sp[ruleBeginDate]' : $("#ruleBeginDate").val().replace(/-/g,""),
			'sp[ruleEndDate]' : $("#ruleEndDate").val().replace(/-/g,""),
			'sp[ruleName]' : $("#ruleName").val(),
			'sp[ruleType]' : $("#ruleTypeVal").val()
		},  
		colNames:["主键","规则名称","规则类型","规则内容","近期触发规则产品","规则生效日期起","规则生效日期止"/*,"操作"*/],        
		colModel:[  { name: 'ruleId', index: 'ruleId', hidden: true, key: true, resizable: true, sortable: false },       
		            { name: 'ruleName', index: 'ruleName', width:180, resizable: true, sortable: false },
		            { name: 'ruleType', index: 'ruleType', resizable: true, sortable: false ,
		            	formatter:function(cellvalue, options, rowObject){
		            		if(cellvalue =="1"){
		            			return "资产配置";
		            		}else if(cellvalue =="2"){
		            			return "投资交易";
		            		}else if(cellvalue =="3"){
		            			return "其他";
		            		}else{
		            			return cellvalue;
		            		}
		            	}
		            },
		            { name: 'ruleContent', index: 'ruleContent', width:450, resizable: true, sortable: false },
		            { name: 'triggerRuleProduct', index: 'triggerRuleProduct', width:220, resizable: true, sortable: false },
		            { name: 'ruleBeginDate', index: 'ruleBeginDate', resizable: true, sortable: false },
		            { name: 'ruleEndDate', index: 'ruleEndDate', resizable: true, sortable: false }/*,
		            { name: 'option', index: 'option', resizable: true, sortable: false }*/
				  ],
		rowNum: 20,
        rowList: [20, 30, 50],
        rownumbers: true,
        rownumWidth: 50,
        prmNames: { search: "search", page: "pageNo", rows: "limit" },
        height: $(window).height()-220,
        width: false,
        autowidth:true,
        editurl: '',
        viewrecords: true,
        cellEdit: false,
        shrinkToFit: true,
        grouping: false,
        jsonReader: {
            root: "items", //结果集
            records: "total", //总记录数 
            total: "pageCount", //总页数
            page: "pageNo", //当前页 
            repeatitems: false // (4) 
        },  
		pager: "#orderRiskMgrListPage",					
		gridComplete: function(){
			
		}
	});
	$orderRiskMgrList.navGrid('#orderRiskMgrListage',{edit:false,add:false,del:false,search:false,refreshstate:'current'});
	$orderRiskMgrList.jqGrid('setFrozenColumns');
	jqGridResize($orderRiskMgrList);
	$(".ui-jqgrid .ui-jqgrid-htable").css("width",$(".ui-jqgrid").width()-1);
	$(".ui-jqgrid .ui-jqgrid-btable").css("width",$(".ui-jqgrid").width()-1);
});

/**
 * 查询按钮
 * 根据条件查询数据
 * @param flag
 */
function queryByCondtion1(flag){
    var postData = $orderRiskMgrList.jqGrid("getGridParam", "postData");
    $.extend(postData, {
		'sp[ruleBeginDate]' : $("#ruleBeginDate").val().replace(/-/g,""),
		'sp[ruleEndDate]' : $("#ruleEndDate").val().replace(/-/g,""),
		'sp[ruleName]' : $("#ruleName").val(),
		'sp[ruleType]' : $("#ruleTypeVal").val()
	});
    if (flag) {
    	$orderRiskMgrList.jqGrid("setGridParam",{"datatype": "json"}).trigger("reloadGrid",[{page:1}]);//重新载入Grid表格
    } else {
    	$orderRiskMgrList.jqGrid("setGridParam",{"datatype": "json"}).trigger("reloadGrid");//重新载入Grid表格
    }
}